varying vec2 v_texcoord;
varying vec4 v_color;
varying vec3 normal;
//varying vec4 position;
varying float attenuation;
varying vec3 lightDirection;
varying vec3 halfVector;

uniform vec3 ambient;
uniform vec3 lightColor;
uniform float shininess;
uniform float strength;
struct MaterialProperties
{
    vec3 emission;
    vec3 ambient;
    vec3 diffuse;
    vec3 specular;
    float shininess;
};
uniform MaterialProperties materialProperty;
uniform float alpha;
void main(){

    float diffuse = max(0.0,dot(normal,lightDirection));
    float specular = max(0.0,dot(normal,halfVector));

    if(diffuse == 0.0)
        specular = 0.0;
    else
        specular = pow(specular,shininess) * strength;

   vec3 scatteredLight = ambient * materialProperty.ambient * attenuation  + lightColor * diffuse * materialProperty.diffuse * attenuation;
   vec3 reflectedLight = lightColor * specular * materialProperty.specular * attenuation;

   vec3 rgb = min(materialProperty.emission + v_color.rgb + scatteredLight + reflectedLight ,vec3(1.0));

   gl_FragColor = vec4(v_color.rgb,alpha);//vec4(rgb,v_color.a);
}
